<template>
  <el-dialog
    v-model="props.dialogVisible"
    title="Tips"
    width="500"
    @update:model-value="updateDialogVisible"
  >
    <el-form :model="punish" label-width="80px">
      <el-form-item label="惩罚内容">
        <el-input v-model="punish.punishDescription" />
      </el-form-item>
      <el-form-item label="权重">
        <el-input v-model="punish.punishWeight" />
      </el-form-item>
  </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="closeDialog">取消</el-button>
        <el-button type="primary" @click="updatePunish">
          更新
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup lang="ts">
import type { Punish } from '@/types/StudentType.ts'
import { defineEmits } from 'vue'
import axios from 'axios'
import { ElMessage } from 'element-plus'
const props = defineProps<{
  dialogVisible: boolean
  punish: Punish
}>()

const emits = defineEmits(['update:dialogVisible','loadData'])

const updateDialogVisible = (value: boolean) => {
  emits('update:dialogVisible', value)
}

const closeDialog = () => {
  emits('update:dialogVisible', false)
}

const updatePunish = async ()=>{
  const res = await axios.post('/api/punish/update',props.punish)
  if (res.data.code === 0){
    ElMessage.success("更新成功")
    closeDialog()
  }else {
    ElMessage.error("更新失败")
  }
}
</script>
<style scoped lang="scss">

</style>
